<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
%>
<%@ include file="/WEB-INF/jsp/common/tags.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>角色管理</title>
<%@ include file="/WEB-INF/jsp/common/ui.jsp"%>
</head>
<body style="visibility: visible;">
	<div id="tb" style="padding: 5px; height: auto">
		<div style="margin-bottom: 5px">
			<a href="javascript:void(0)" class="easyui-linkbutton"
				iconCls="icon-add" plain="true" id="addbtn">新增</a> &nbsp; &nbsp; <a
				href="javascript:void(0)" class="easyui-linkbutton"
				iconCls="icon-edit" plain="true" id="editbtn">修改</a> &nbsp; &nbsp; <a
				href="javascript:void(0)" class="easyui-linkbutton"
				iconCls="icon-remove" plain="true" id="delbtn">删除</a> &nbsp; &nbsp;
			<shiro:hasPermission name="/assignPermissions.do">
				<a href="javascript:void(0)" class="easyui-linkbutton"
					iconCls="icon-edit" plain="true" id="fpqxbtn">分配权限</a>
			</shiro:hasPermission>
		</div>
		<form:form action="" method="post" id="searchForm">
      角色名称:   
        <input class="easyui-validatebox" type="text" id="name"
				name="name" data-options="">
			<a href="javascript:void(0)" class="easyui-linkbutton"
				id="submit_search" iconCls="icon-search"">Search</a>
		</form:form>
	</div>

	<table id="tt" class="easyui-datagrid"
		style="width: 480px; height: 320px"
		data-options="fit:true,collapsible:true,rownumbers:true,url:'<%=path%>/role/list',fitColumns:true,singleSelect:false,sortOrder:'desc',sortName:'clintname',pagination:true,toolbar:'#tb'"
		title="数据加载列表">
		<thead>
			<tr>
				<th data-options="field:'ck',checkbox:true"></th>
				<th field="id">编号</th>
				<th field="name" data-options="width:$(this).width()*0.2">角色名称</th>
				<th field="description" data-options="width:$(this).width()*0.2">备注</th>
				<th field="createTime" align="center"
					data-options="width:$(this).width()*0.2">创建时间</th>
			</tr>
		</thead>
	</table>
</body>

<script type="text/javascript">
	function addPanel(url, title) {
		var tab = parent.$('#tabs').tabs('exists', title);
		if (tab) {
			//若存在，则直接打开
			parent.$('#tabs').tabs('select', title);
		} else {
			parent
					.$('#tabs')
					.tabs(
							'add',
							{
								title : title,
								content : "<iframe width='100%' height='100%'  id='iframe' frameborder='0' scrolling='auto'  src='<%=path%>"
										+ url + "'></iframe>",
								closable : true
							});

		}

	}

	//title 标题_编号
	function editPanel(url, title) {
		parent
				.$('#tabs')
				.tabs(
						'add',
						{
							title : title,
							content : "<iframe width='100%' height='100%'  id='iframe' frameborder='0' scrolling='auto'  src='<%=path%>"
									+ url + "'></iframe>",
							closable : true
						});

	}

	//post提交批量删除信息并弹出处理结果
	function delDatas(delList, listId, address) {
		$.messager.confirm('提示信息', '确定要删除选中行吗？', function(b) {
			if (b) {
				$.ajax({
					url : address,

					type : 'POST',

					data : {
						ids : delList
					},

					dataType : 'json',

					timeout : 15000,

					error : function() {
						alert('Error ');
					},

					success : function(result) {

						$.messager.alert('信息提示', result.resultMsg, 'info');
						$(listId).datagrid('reload');

					}

				});

			}
		});
	}

	var toolbar = [ {
		text : '新增',
		iconCls : 'icon-add',
		handler : function() {

		}
	}, {
		text : '修改',
		iconCls : 'icon-edit',
		handler : function() {

		}
	}, '-', {
		text : '删除',
		iconCls : 'icon-remove',
		handler : function() {

		}
	} ];

	$(function() {

		$("#submit_search").click(function() {
			var f = $('#searchForm').form('validate');
			if (f) {
				$('#tt').datagrid('load', {
					"name" : $('#name').val()
				});
			} else {

				return f;
			}

		});

		//$('#tt').datagrid('reload',{pageindex:11});
		$("#addbtn").click(function() {
			addPanel('/role/add', '新增角色');
		});

		$("#editbtn").click(
				function() {
					var rows = $("#tt").datagrid("getSelections"); // 获取所有选中的行
					var parks = [];
					if (rows == 0) {
						$.messager.alert("系统提示", "请选择要修改的数据!", "info");
						return;
					} else if (rows.length > 1) {
						$.messager.alert("系统提示", "一次只能修改一条数据!", "info");
						return;

					} else {
						for (var i = 0; i < rows.length; i++) {
							parks.push(rows[i].id);
						}
						var parkparams = parks.join(',');

						editPanel('/role/edit?id=' + parkparams, '修改角色_'
								+ parkparams);

					}
				});

		$("#delbtn").click(function() {
			var rows = $("#tt").datagrid("getSelections"); // 获取所有选中的行
			var parks = [];
			if (rows == 0) {
				$.messager.alert("系统提示", "请选择要删除的数据!", "info");
				return;

			} else {
				for (var i = 0; i < rows.length; i++) {
					parks.push(rows[i].id);
				}
				var parkparams = parks.join(',');
				delDatas(parkparams, '#tt', 'deleteRole.do');
			}
		});

		$("#fpqxbtn").click(
				function() {
					var rows = $("#tt").datagrid("getSelections"); // 获取所有选中的行
					var parks = [];
					if (rows == 0) {
						$.messager.alert("系统提示", "请选择要分配的数据!", "info");
						return;
					} else if (rows.length > 1) {
						$.messager.alert("系统提示", "一次只能分配一条数据!", "info");
						return;

					} else {
						for (var i = 0; i < rows.length; i++) {
							parks.push(rows[i].id);
						}
						var parkparams = parks.join(',');

						editPanel('assignPermissions.do?id=' + parkparams,
								'修改权限_' + parkparams);

					}
				});

	});
</script>
</html>